package be.ipl.finito.domaine;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@SuppressWarnings("serial")
@Entity
@Table(name = "CASES", schema = "FINITO")
public class Case implements Serializable, Comparable<Case> {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "case_id")
	private int id;

	@NotNull
	private int valeur;

	@NotNull
	private int position;

	@ManyToOne
	@JoinColumn(name = "JETON_ID")
	private Jeton jeton;

	protected Case() {

	}

	public Case(int valeur, int position) {
		super();
		this.valeur = valeur;
		this.position = position;
	}

	public int getId() {
		return id;
	}

	public int getValeur() {
		return valeur;
	}

	public Jeton getJeton() {
		return jeton;
	}

	public void setJeton(Jeton jeton) {
		this.jeton = jeton;
	}

	public int getPosition() {
		return position;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Case other = (Case) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public int compareTo(Case o) {
		return position - o.position;
	}

}
